package com.xsdl.template;

public abstract class AbstractTemplateServiceImpl<T> {

    public void delete(String uuid) {
        System.out.println("***执行了" + getResourceName() + "资源的删除操作,主键标识:" + uuid);
        T entity = getEntity(uuid);
        if (entity == null) {
            System.out.println("***执行了" + getResourceName() + "资源的删除操作,主键标识:" + uuid + ",但未找到对应的数据");
            return;
        }
        if (entity instanceof BaseEntity) {
            if ("1".equals(((BaseEntity) entity).getDeleted())) {
                System.out.println("***执行了" + getResourceName() + "资源的删除操作,主键标识:" + uuid + ",但数据已被删除");
                return;
            }
            BaseEntity baseEntity = (BaseEntity) entity;
            baseEntity.setDeleted("1");
            saveToDataBase(entity);
        }
    }

    protected abstract T getEntity(String uuid);

    protected abstract T saveToDataBase(T entity);

    protected abstract String getResourceName();

}
